﻿using System;

namespace Demo
{
    class Program
    {
        static void Main(string[] args)
        {

            var d = new GBBuilder();
            var d2 = new EMBuilder();

            ActorBuilder builder = (ActorBuilder)d2;
            ActorController director = new ActorController();
            Actor actor = director.Construct(builder);

            Console.WriteLine("角色类型：{0}", actor.Type);
            Console.WriteLine("角色性别：{0}", actor.Sex);
            Console.WriteLine("角色面容：{0}", actor.Face);
            Console.WriteLine("角色服装：{0}", actor.Costume);
            Console.WriteLine("角色发型：{0}", actor.HairStyle);







        }
    }

    /// <summary>
    /// Actor 角色类 ： 产品
    /// </summary>
    public class Actor
    {
        // 角色类型
        public string Type { get; set; }
        // 性别
        public string Sex { get; set; }
        // 脸型
        public string Face { get; set; }
        // 服装
        public string Costume { get; set; }
        // 发型
        public string HairStyle { get; set; }
    }

    /// <summary>
    ///  抽象建造者
    /// </summary>
    public abstract class ActorBuilder
    {
        protected Actor actor = new Actor();

        public abstract void BuildType();
        public abstract void BuildSex();
        public abstract void BuildFace();
        public abstract void BuildCostume();
        public abstract void BuildHairStyle();

        // 工厂方法 ： 返回一个完整的游戏角色对象
        public Actor CreateActor()
        {
            return actor;
        }
    }

    /// <summary>
    /// 丐帮 ：具体建造者
    /// </summary>
    public class GBBuilder : ActorBuilder
    {
        public override void BuildCostume()
        {
            actor.Costume = "麻衣";
        }

        public override void BuildFace()
        {
            actor.Face = "勇猛";
        }

        public override void BuildHairStyle()
        {
            actor.HairStyle = "乱发";
        }

        public override void BuildSex()
        {
            actor.Sex = "男";
        }

        public override void BuildType()
        {
            actor.Type = "丐帮";
        }
    }


    /// <summary>
    /// 峨眉 ：具体建造者
    /// </summary>
    public class EMBuilder : ActorBuilder
    {
        public override void BuildCostume()
        {
            actor.Costume = "红色长裙";
        }

        public override void BuildFace()
        {
            actor.Face = "漂亮";
        }

        public override void BuildHairStyle()
        {
            actor.HairStyle = "长发飘飘";
        }

        public override void BuildSex()
        {
            actor.Sex = "女";
        }

        public override void BuildType()
        {
            actor.Type = "峨眉派";
        }
    }


    /// <summary>
    /// 游戏角色创建控制器：指挥者(Director)
    /// </summary>
    public class ActorController
    {
        /// <summary>
        /// 逐步构建复杂产品对象
        /// </summary>
        public Actor Construct(ActorBuilder builder)
        {
            builder.BuildType();
            builder.BuildSex();
            builder.BuildFace();
            builder.BuildCostume();
            builder.BuildHairStyle();

            return builder.CreateActor(); ;
        }
    }


}
